$(function () {


});


function examine(obj, id) {
    layer.confirm('要通过审核该店铺吗？', function (index) {

        $.ajax({
            url: changestatus_url,
            data: {"storeId": id},
            type: "POST",
            dataType: "json",
            success: function (data) {
                var dataid = "'" + data.data + "'";
                if (data.status == 1) {
                    $(obj).parents("tr").find(".td-status").find('span').removeClass('layui-btn-danger').html('审核通过');
                    $(obj).parents("tr").find(".td-manage").html("<a onclick=\"handle_stop(this,"+dataid+")\" href=\"javascript:;\" title=\"关停店铺\">\n" +
                        "<i class=\"layui-icon\">&#xe631;</i>\n" +
                        "</a>");
                    layer.msg('审核成功', {icon: 6, time: 2000});
                } else {
                    layer.msg(data.message);
                }

            },
            error: function (data) {
                layer.msg("服务器无响应");
            }
        });
    });
}


/**
 * 启用
 */
function handle_start(obj, id) {
    layer.confirm('确认要开启该店铺吗？', function (index) {
        $.ajax({
            url: changestatus_url,
            data: {"storeId": id},
            type: "POST",
            dataType: "json",
            success: function (data) {
                var dataid = "'" + data.data + "'";
                if (data.status == 1) {
                    $(obj).parents("tr").find(".td-status").find('span').removeClass('layui-btn-disabled').html('审核通过');
                    $(obj).parents("tr").find(".td-manage").html("<a onclick=\"handle_stop(this,"+dataid+")\" href=\"javascript:;\" title=\"关停店铺\">\n" +
                        "<i class=\"layui-icon\">&#xe631;</i>\n" +
                        "</a>");
                    layer.msg('启用成功', {icon: 1, time: 2000});
                } else {
                    layer.msg(data.message);
                }
            },
            error: function (data) {
                layer.msg("服务器无响应");
            }
        });
    });
}

/**
 * 关停店铺
 */
function handle_stop(obj, id) {
    layer.confirm('确认要关停该店铺吗？', function (index) {
        //发异步删除数据
        $.ajax({
            url: changestatus_url,
            data: {"storeId": id},
            type: "POST",
            dataType: "json",
            success: function (data) {
                var dataid = "'" + data.data + "'";
                if (data.status == 1) {
                    $(obj).parents("tr").find(".td-status").find('span').addClass('layui-btn-disabled').html('已经关停');
                    $(obj).parents("tr").find(".td-manage").html("<a onclick=\"handle_start(this,"+dataid+")\" href=\"javascript:;\" title=\"开启店铺\">\n" +
                        "<i class=\"layui-icon\">&#xe631;</i>\n" +
                        "</a>");
                    layer.msg('已关停', {icon: 1, time: 2000});
                } else {
                    layer.msg(data.message);
                }
            },
            error: function (data) {
                layer.msg("服务器无响应");
            }
        });
    });
}
